package com.schoolegard.services.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.schoolegard.services.UpgradeToDeviceService;
import com.schoolgard.dao.JobModeDao;
import com.schoolgard.dao.JobStatusDao;
import com.schoolgard.dao.UpgradeToDeviceDao;
import com.schoolgard.entitybean.JobMode;
import com.schoolgard.entitybean.JobStatus;
import com.schoolgard.entitybean.UpgradeToDevice;

public class UpgradeToDeviceServiceImpl implements UpgradeToDeviceService {
	private static Logger logger = Logger.getLogger(UpgradeToDeviceServiceImpl.class);
	
	private UpgradeToDeviceDao upgradeToDeviceDao;
	private JobModeDao jobModeDao;
	private JobStatusDao jobStatusDao;
	
	@Override
	public List<UpgradeToDevice> findAll() {
		DetachedCriteria criteria = DetachedCriteria.forClass(UpgradeToDevice.class);
		criteria.addOrder(Order.desc("createDatetime"));
		return upgradeToDeviceDao.findByCriteria(criteria);
	}
	@Override
	public List<JobStatus> findJobStatus() {
		return jobStatusDao.findAll();
	}
	@Override
	public List<JobMode> findJobMode() {
		return jobModeDao.findAll();
	}
	@Override
	public JobMode findJobModeById(Long modeId) {
		return jobModeDao.findById(modeId);
	}
	@Override
	public JobStatus findjobStatusById(Long statusId) {
		return jobStatusDao.findById(statusId);
	}
	@Override
	public void saveOrUpdate(UpgradeToDevice upgradeToDevice) {
		upgradeToDeviceDao.createOrModify(upgradeToDevice);
	}
	@Override
	public void delete(Long id) {
		upgradeToDeviceDao.remove(findById(id));
	}
	@Override
	public UpgradeToDevice findById(Long id) {
		return upgradeToDeviceDao.findById(id);
	}
	
	public void setUpgradeToDeviceDao(UpgradeToDeviceDao upgradeToDeviceDao) {
		this.upgradeToDeviceDao = upgradeToDeviceDao;
	}
	public void setJobModeDao(JobModeDao jobModeDao) {
		this.jobModeDao = jobModeDao;
	}
	public void setJobStatusDao(JobStatusDao jobStatusDao) {
		this.jobStatusDao = jobStatusDao;
	}
	
	public void saveAll(List<UpgradeToDevice> utds) {
		for(UpgradeToDevice udt : utds) {
			saveOrUpdate(udt);
		}
	}
}
